/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.

package com.kingdee.eas.custom.fi.arap.app;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemCollection;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.bos.metadata.entity.SelectorItemInfo;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.basedata.assistant.CashDiscountCollection;
import com.kingdee.eas.basedata.assistant.CashDiscountFactory;
import com.kingdee.eas.basedata.assistant.CashDiscountInfo;
import com.kingdee.eas.basedata.assistant.CurrencyCollection;
import com.kingdee.eas.basedata.assistant.CurrencyFactory;
import com.kingdee.eas.basedata.assistant.CurrencyInfo;
import com.kingdee.eas.basedata.assistant.ExchangeRateFactory;
import com.kingdee.eas.basedata.assistant.ExchangeRateInfo;
import com.kingdee.eas.basedata.assistant.ExchangeTableInfo;
import com.kingdee.eas.basedata.assistant.ICashDiscount;
import com.kingdee.eas.basedata.assistant.ICurrency;
import com.kingdee.eas.basedata.assistant.IExchangeRate;
import com.kingdee.eas.basedata.assistant.IMeasureUnit;
import com.kingdee.eas.basedata.assistant.IPaymentType;
import com.kingdee.eas.basedata.assistant.ISettlementType;
import com.kingdee.eas.basedata.assistant.MeasureUnitCollection;
import com.kingdee.eas.basedata.assistant.MeasureUnitFactory;
import com.kingdee.eas.basedata.assistant.MeasureUnitInfo;
import com.kingdee.eas.basedata.assistant.PaymentTypeCollection;
import com.kingdee.eas.basedata.assistant.PaymentTypeFactory;
import com.kingdee.eas.basedata.assistant.PaymentTypeInfo;
import com.kingdee.eas.basedata.assistant.SettlementTypeCollection;
import com.kingdee.eas.basedata.assistant.SettlementTypeFactory;
import com.kingdee.eas.basedata.assistant.SettlementTypeInfo;
import com.kingdee.eas.basedata.master.account.AccountViewCollection;
import com.kingdee.eas.basedata.master.account.AccountViewFactory;
import com.kingdee.eas.basedata.master.account.AccountViewInfo;
import com.kingdee.eas.basedata.master.account.IAccountView;
import com.kingdee.eas.basedata.master.auxacct.AsstActTypeCollection;
import com.kingdee.eas.basedata.master.auxacct.AsstActTypeFactory;
import com.kingdee.eas.basedata.master.auxacct.AsstActTypeInfo;
import com.kingdee.eas.basedata.master.auxacct.IAsstActType;
import com.kingdee.eas.basedata.master.material.AsstAttrValueCollection;
import com.kingdee.eas.basedata.master.material.AsstAttrValueFactory;
import com.kingdee.eas.basedata.master.material.AsstAttrValueInfo;
import com.kingdee.eas.basedata.master.material.IAsstAttrValue;
import com.kingdee.eas.basedata.master.material.IMaterial;
import com.kingdee.eas.basedata.master.material.IMultiMeasureUnit;
import com.kingdee.eas.basedata.master.material.MaterialCollection;
import com.kingdee.eas.basedata.master.material.MaterialFactory;
import com.kingdee.eas.basedata.master.material.MaterialInfo;
import com.kingdee.eas.basedata.master.material.MultiMeasureUnitFactory;
import com.kingdee.eas.basedata.master.material.MultiMeasureUnitInfo;
import com.kingdee.eas.basedata.org.AdminOrgUnitCollection;
import com.kingdee.eas.basedata.org.AdminOrgUnitFactory;
import com.kingdee.eas.basedata.org.AdminOrgUnitInfo;
import com.kingdee.eas.basedata.org.CompanyOrgUnitFactory;
import com.kingdee.eas.basedata.org.CompanyOrgUnitInfo;
import com.kingdee.eas.basedata.org.IAdminOrgUnit;
import com.kingdee.eas.basedata.org.ICompanyOrgUnit;
import com.kingdee.eas.basedata.org.IPurchaseOrgUnit;
import com.kingdee.eas.basedata.org.ISaleOrgUnit;
import com.kingdee.eas.basedata.org.PurchaseOrgUnitCollection;
import com.kingdee.eas.basedata.org.PurchaseOrgUnitFactory;
import com.kingdee.eas.basedata.org.PurchaseOrgUnitInfo;
import com.kingdee.eas.basedata.org.SaleOrgUnitCollection;
import com.kingdee.eas.basedata.org.SaleOrgUnitFactory;
import com.kingdee.eas.basedata.org.SaleOrgUnitInfo;
import com.kingdee.eas.basedata.person.IPerson;
import com.kingdee.eas.basedata.person.PersonCollection;
import com.kingdee.eas.basedata.person.PersonFactory;
import com.kingdee.eas.basedata.person.PersonInfo;
import com.kingdee.eas.basedata.scm.common.BillTypeCollection;
import com.kingdee.eas.basedata.scm.common.BillTypeFactory;
import com.kingdee.eas.basedata.scm.common.BillTypeInfo;
import com.kingdee.eas.basedata.scm.common.DiscountModeEnum;
import com.kingdee.eas.basedata.scm.common.ExpenseItemCollection;
import com.kingdee.eas.basedata.scm.common.ExpenseItemFactory;
import com.kingdee.eas.basedata.scm.common.ExpenseItemInfo;
import com.kingdee.eas.basedata.scm.common.IBillType;
import com.kingdee.eas.basedata.scm.common.IExpenseItem;
import com.kingdee.eas.basedata.scm.sd.sale.ISaleGroup;
import com.kingdee.eas.basedata.scm.sd.sale.SaleGroupCollection;
import com.kingdee.eas.basedata.scm.sd.sale.SaleGroupFactory;
import com.kingdee.eas.basedata.scm.sd.sale.SaleGroupInfo;
import com.kingdee.eas.basedata.scm.sm.pur.IPurchaseGroup;
import com.kingdee.eas.basedata.scm.sm.pur.PurchaseGroupCollection;
import com.kingdee.eas.basedata.scm.sm.pur.PurchaseGroupFactory;
import com.kingdee.eas.basedata.scm.sm.pur.PurchaseGroupInfo;
import com.kingdee.eas.common.client.SysContext;
import com.kingdee.eas.fi.ap.OtherBillInfo;
import com.kingdee.eas.fi.ap.OtherBillPlanCollection;
import com.kingdee.eas.fi.ap.OtherBillPlanInfo;
import com.kingdee.eas.fi.ap.OtherBillType;
import com.kingdee.eas.fi.ap.OtherBillentryCollection;
import com.kingdee.eas.fi.ap.OtherBillentryInfo;
import com.kingdee.eas.fi.ar.OtherBillTypeEnum;
import com.kingdee.eas.fi.arap.util.ArApBillHelper;
import com.kingdee.eas.fi.cas.IPaymentBillType;
import com.kingdee.eas.fi.cas.IReceivingBillType;
import com.kingdee.eas.fi.cas.PaymentBillTypeCollection;
import com.kingdee.eas.fi.cas.PaymentBillTypeFactory;
import com.kingdee.eas.fi.cas.PaymentBillTypeInfo;
import com.kingdee.eas.fi.cas.ReceivingBillTypeCollection;
import com.kingdee.eas.fi.cas.ReceivingBillTypeFactory;
import com.kingdee.eas.fi.cas.ReceivingBillTypeInfo;
import com.kingdee.eas.tools.datatask.core.TaskExternalException;
import com.kingdee.eas.tools.datatask.runtime.DataToken;
import com.kingdee.eas.util.ResourceBase;
import com.kingdee.eas.util.app.ContextUtil;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.util.BaseException;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import javax.sql.RowSet;

public class ARAPImportHelper
{

    public ARAPImportHelper()
    {
    }

    public static AdminOrgUnitInfo getAdminOrgUnitInfo(Context ctx, Hashtable hsData, String field)
        throws BOSException, TaskExternalException
    {
        String number = getDataString(hsData, field);
        if(number != null)
        {
            IAdminOrgUnit iadminOrg = AdminOrgUnitFactory.getLocalInstance(ctx);
            AdminOrgUnitCollection collection = iadminOrg.getAdminOrgUnitCollection(getEntityViewByNum(number));
            if(collection != null && collection.size() > 0)
                return collection.get(0);
            else
            
                throw new TaskExternalException(getString("AdminOrg_Is_Error", ctx));
        } else
        {
            return null;
        }
    }

    public static PersonInfo getPersonInfo(Context ctx, Hashtable hsData, String field)
        throws BOSException, TaskExternalException
    {
        String number = getDataString(hsData, field);
        if(number != null)
        {
            IPerson iPerson = PersonFactory.getLocalInstance(ctx);
            PersonCollection collection = iPerson.getPersonCollection(getEntityViewByNum(number));
            if(collection != null && collection.size() > 0)
                return collection.get(0);
            else
                throw new TaskExternalException(getString("Person_Is_Error", ctx));
        } else
        {
            return null;
        }
    }

    public static SaleOrgUnitInfo getSaleOrgUnitInfo(Context ctx, Hashtable hsData, String field)
        throws BOSException, TaskExternalException
    {
        String number = getDataString(hsData, field);
        if(number != null)
        {
            ISaleOrgUnit iSaleOrg = SaleOrgUnitFactory.getLocalInstance(ctx);
            SaleOrgUnitCollection collection = iSaleOrg.getSaleOrgUnitCollection(getEntityViewByNum(number));
            if(collection != null && collection.size() > 0)
                return collection.get(0);
            else
                throw new TaskExternalException(getString("SaleOrg_Is_Error", ctx));
        } else
        {
            return null;
        }
    }

    public static PurchaseOrgUnitInfo getPurchaseOrg(Context ctx, Hashtable hsData, String field)
        throws BOSException, TaskExternalException
    {
        PurchaseOrgUnitInfo info = null;
        String number = getDataString(hsData, field);
        if(number != null)
        {
            IPurchaseOrgUnit ipurOrg = PurchaseOrgUnitFactory.getLocalInstance(ctx);
            PurchaseOrgUnitCollection collection = ipurOrg.getPurchaseOrgUnitCollection(getEntityViewByNum(number));
            if(collection != null && collection.size() > 0)
                info = collection.get(0);
            else
                throw new TaskExternalException(getString("PurOrg_Is_Error", ctx));
        }
        return info;
    }

    public static AsstActTypeInfo getAsstActTypeInfo(Context ctx, Hashtable hsData, String field)
        throws BOSException, TaskExternalException
    {
        String number = getDataString(hsData, field);
        if(number == null)
            throw new TaskExternalException(getString("AsstActTypeID_Null", ctx));
        AsstActTypeInfo asstActTypeInfo = null;
        if(number != null)
        {
            IAsstActType iAsstActType = AsstActTypeFactory.getLocalInstance(ctx);
            EntityViewInfo viewInfo = getEntityViewByNum(number);
            viewInfo.getSelector().add(new SelectorItemInfo("*"));
            AsstActTypeCollection collection = iAsstActType.getAsstActTypeCollection(viewInfo);
            if(collection != null && collection.size() > 0)
                asstActTypeInfo = collection.get(0);
        }
        if(asstActTypeInfo == null)
            throw new TaskExternalException(getString("AsstActTypeID_Wrong", ctx));
        else
            return asstActTypeInfo;
    }

    public static CashDiscountInfo getCashDiscountInfo(Context ctx, Hashtable hsData, String field)
        throws BOSException, TaskExternalException
    {
        String number = getDataString(hsData, field);
        if(number != null)
        {
            ICashDiscount iCashDiscount = CashDiscountFactory.getLocalInstance(ctx);
            CashDiscountCollection collection = iCashDiscount.getCashDiscountCollection(getEntityViewByNum(number));
            if(collection != null && collection.size() > 0)
                return collection.get(0);
            else
                throw new TaskExternalException(getString("CashDiscount_Is_Error", ctx));
        } else
        {
            return null;
        }
    }

    public static SettlementTypeInfo getSettlementTypeInfo(Context ctx, Hashtable hsData, String field)
        throws BOSException, TaskExternalException
    {
        String number = getDataString(hsData, field);
        if(number != null)
        {
            ISettlementType isettlement = SettlementTypeFactory.getLocalInstance(ctx);
            SettlementTypeCollection collection = isettlement.getSettlementTypeCollection(getEntityViewByNum(number));
            if(collection != null && collection.size() > 0)
                return collection.get(0);
            else
                throw new TaskExternalException(getString("SettleType_Is_Error", ctx));
        } else
        {
            return null;
        }
    }

    public static CurrencyInfo getCurrencyInfo(Context ctx, Hashtable hsData, String field)
        throws BOSException, TaskExternalException
    {
        CurrencyInfo currency = null;
        String number = getDataString(hsData, field);
        if(number == null)
            throw new TaskExternalException(getString("FCurrencyID_IsNull", ctx));
        if(number != null)
        {
            ICurrency icurreny = CurrencyFactory.getLocalInstance(ctx);
            CurrencyCollection collection = icurreny.getCurrencyCollection(getEntityViewByNum(number));
            if(collection != null && collection.size() > 0)
                currency = collection.get(0);
        }
        if(currency == null)
        {
            String msg = getString("FieldEmpty_Wrong", ctx);
            msg = MessageFormat.format(msg, new String[] {
                field
            });
            throw new TaskExternalException(msg);
        } else
        {
            return currency;
        }
    }

    public static RowSet getAsstActByNumber(Context ctx, String tableName, String number)
        throws BOSException
    {
        String lang = ctx.getLocale().getLanguage();
        StringBuffer sql = new StringBuffer();
        sql.append("select top 1 FId as fid, ");
        sql.append("FName_").append(lang).append(" as fname ");
        sql.append("from ");
        sql.append(tableName).append(" where FNumber = ?");
        List vs = new ArrayList();
        vs.add(number);
        RowSet result = DbUtil.executeQuery(ctx, sql.toString(), vs.toArray());
        return result;
    }

    public static PaymentTypeInfo getPaymentTypeInfo(Context ctx, Hashtable hsData, String field)
        throws BOSException, TaskExternalException
    {
        PaymentTypeInfo payType = null;
        String number = getDataString(hsData, field);
        if(number == null)
            throw new TaskExternalException(getString("PaymentType_Is_Null", ctx));
        if(number != null)
        {
            PaymentTypeCollection payColl = PaymentTypeFactory.getLocalInstance(ctx).getPaymentTypeCollection(getEntityViewByNum(number));
            if(payColl != null && payColl.size() > 0)
                payType = payColl.get(0);
        }
        if(payType == null)
            throw new TaskExternalException(getString("PaymentType_Is_Error", ctx));
        else
            return payType;
    }

    private static EntityViewInfo getEntityViewByNum(String number)
    {
        EntityViewInfo entityView = new EntityViewInfo();
        entityView.getSelector().add(new SelectorItemInfo("id"));
        entityView.getSelector().add(new SelectorItemInfo("number"));
        entityView.getSelector().add(new SelectorItemInfo("name"));
        FilterInfo filter = new FilterInfo();
        filter.getFilterItems().add(new FilterItemInfo("number", number));
        entityView.setFilter(filter);
        return entityView;
    }

    public static SaleGroupInfo getSaleGroupInfo(Context ctx, Hashtable hsData, String field)
        throws BOSException, TaskExternalException
    {
        String number = getDataString(hsData, field);
        SaleGroupInfo saleGroup = null;
        if(number != null)
        {
            SaleGroupCollection saleColl = SaleGroupFactory.getLocalInstance(ctx).getSaleGroupCollection(getEntityViewByNum(number));
            if(saleColl != null && saleColl.size() > 0)
                saleGroup = saleColl.get(0);
            else
                throw new TaskExternalException(getString("SaleGroup_Is_Error", ctx));
        }
        return saleGroup;
    }

    public static PurchaseGroupInfo getPurchaseGroupInfo(Context ctx, Hashtable hsData, String field)
        throws BOSException, TaskExternalException
    {
        String number = getDataString(hsData, field);
        PurchaseGroupInfo purGroup = null;
        if(number != null)
        {
            PurchaseGroupCollection purGroupColl = PurchaseGroupFactory.getLocalInstance(ctx).getPurchaseGroupCollection(getEntityViewByNum(number));
            if(purGroupColl != null && purGroupColl.size() > 0)
                purGroup = purGroupColl.get(0);
            else
                throw new TaskExternalException(getString("PurGroup_Is_Error", ctx));
        }
        return purGroup;
    }

    public static MaterialInfo getMaterialInfo(Context ctx, Hashtable hsData, String field)
        throws TaskExternalException, BOSException
    {
        MaterialInfo info = null;
        String number = getDataString(hsData, field);
        if(number != null)
        {
            IMaterial iMaterial = MaterialFactory.getLocalInstance(ctx);
            EntityViewInfo view = getEntityViewByNum(number);
            view.getSelector().add(new SelectorItemInfo("baseUnit"));
            MaterialCollection collection = iMaterial.getMaterialCollection(view);
            if(collection != null && collection.size() > 0)
                info = collection.get(0);
            else
                throw new TaskExternalException(getString("Material_Wrong", ctx));
        }
        return info;
    }

    public static MeasureUnitInfo getMeasureUnitInfo(Context ctx, Hashtable hsData, String field)
        throws TaskExternalException, BOSException
    {
        String number = getDataString(hsData, field);
        MeasureUnitInfo info = null;
        if(number != null)
        {
            IMeasureUnit iMeasureUnit = MeasureUnitFactory.getLocalInstance(ctx);
            MeasureUnitCollection collection = iMeasureUnit.getMeasureUnitCollection(getEntityViewByNum(number));
            if(collection != null && collection.size() > 0)
                info = collection.get(0);
            else
                throw new TaskExternalException(getString("MeasureUnit_Wrong", ctx));
        }
        return info;
    }

    public static AsstAttrValueInfo getAsstAttrValueInfo(Context ctx, Hashtable hsData, String field)
        throws TaskExternalException, BOSException
    {
        String number = getDataString(hsData, field);
        AsstAttrValueInfo info = null;
        if(number != null)
        {
            IAsstAttrValue iAsstAttrValue = AsstAttrValueFactory.getLocalInstance(ctx);
            AsstAttrValueCollection collection = iAsstAttrValue.getAsstAttrValueCollection(getEntityViewByNum(number));
            if(collection != null && collection.size() > 0)
                info = collection.get(0);
        }
        return info;
    }

    public static AccountViewInfo getAccountViewInfo(Context ctx, Hashtable hsData, String field)
        throws TaskExternalException, BOSException
    {
        String number = getDataString(hsData, field);
        AccountViewInfo info = null;
        if(number != null)
        {
            IAccountView iAccount = AccountViewFactory.getLocalInstance(ctx);
            EntityViewInfo viewInfo = getEntityViewByNum(number);
            CompanyOrgUnitInfo company = ContextUtil.getCurrentFIUnit(ctx);
            viewInfo.getFilter().getFilterItems().add(new FilterItemInfo("companyID.id", company.getId().toString()));
            AccountViewCollection collection = iAccount.getAccountViewCollection(viewInfo);
            if(collection != null && collection.size() > 0)
            {
                info = collection.get(0);
            } else
            {
                String msg = getString("FieldId_Wrong", ctx);
                msg = MessageFormat.format(msg, new String[] {
                    field
                });
                throw new TaskExternalException(msg);
            }
        }
        return info;
    }

    public static ExpenseItemInfo getExpenseItemInfo(Context ctx, Hashtable hsData, String field)
        throws TaskExternalException, BOSException
    {
        ExpenseItemInfo info = null;
        String number = getDataString(hsData, field);
        if(number != null)
        {
            IExpenseItem iExpenseItem = ExpenseItemFactory.getLocalInstance(ctx);
            ExpenseItemCollection collection = iExpenseItem.getExpenseItemCollection(getEntityViewByNum(number));
            if(collection != null && collection.size() > 0)
                info = collection.get(0);
            else
                throw new TaskExternalException(getString("ExpenseItem_Wrong", ctx));
        }
        return info;
    }

    public static DiscountModeEnum getDiscountTypeInfo(Context ctx, Hashtable hsData, String field)
        throws TaskExternalException
    {
        String str = getDataString(hsData, field);
        DiscountModeEnum retValue = DiscountModeEnum.NULL;
        if(str != null && str.length() > 0)
        {
            int value = 0;
            try
            {
                value = Integer.parseInt(str);
            }
            catch(Exception e)
            {
                throw new TaskExternalException(getString("DiscountType_Error", ctx));
            }
            switch(value)
            {
            case 0: // '\0'
                retValue = DiscountModeEnum.PERCENT;
                break;

            case 1: // '\001'
                retValue = DiscountModeEnum.PERUNIT;
                break;

            default:
                throw new TaskExternalException(getString("DiscountType_Error", ctx));

            case -1: 
                break;
            }
        }
        return retValue;
    }

    public static boolean getDataboolean(Hashtable hsData, String field)
    {
        String str = getDataString(hsData, field);
        if(str == null)
            return false;
        return str.equals("Y") || str.equals("1");
    }

    public static BigDecimal getBaseUnitQty(Context ctx, MeasureUnitInfo mui, MaterialInfo mi, BigDecimal qty)
        throws BaseException
    {
        BigDecimal coefficient = new BigDecimal("1.00");
        BigDecimal baseQty = new BigDecimal("0.00000");
        if(qty != null)
            baseQty = qty;
        else
            qty = baseQty;
        MultiMeasureUnitInfo mulUnit = getMulUnit(ctx, mui, mi);
        if(mulUnit != null)
        {
            coefficient = mulUnit.getBaseConvsRate();
            if(coefficient != null)
            {
                baseQty = qty.multiply(coefficient);
                MeasureUnitInfo baseUnit = mi.getBaseUnit();
                if(baseUnit == null)
                {
                    IMaterial im = MaterialFactory.getLocalInstance(ctx);
                    baseUnit = im.getMaterialInfo(new ObjectUuidPK(mi.getId())).getBaseUnit();
                }
                mulUnit = getMulUnit(ctx, baseUnit, mi);
                int precision = mulUnit.getQtyPrecision();
                baseQty = baseQty.setScale(precision, 4);
            }
        }
        return baseQty;
    }

    public static MultiMeasureUnitInfo getMulUnit(Context ctx, MeasureUnitInfo mui, MaterialInfo mi)
        throws BaseException
    {
        MultiMeasureUnitInfo mulUnit = null;
        IMultiMeasureUnit immu = MultiMeasureUnitFactory.getLocalInstance(ctx);
        if(mui != null && mi != null)
            mulUnit = immu.getMultiUnit(mi.getId().toString(), mui.getId().toString());
        return mulUnit;
    }

    private static ObjectUuidPK getCompanyPK(Context ctx)
        throws TaskExternalException
    {
        CompanyOrgUnitInfo comobj = ContextUtil.getCurrentFIUnit(ctx);
        if(comobj == null || comobj.isIsOnlyUnion())
            throw new TaskExternalException(getString("changBizCom", ctx));
        else
            return new ObjectUuidPK(BOSUuid.read(comobj.get("id").toString()));
    }

    protected static ExchangeRateInfo getExchangeRateInfo(Context ctx, CompanyOrgUnitInfo companyOrgUnitInfo, CurrencyInfo currencyInfo)
        throws Exception
    {
        IExchangeRate iexchangRate = null;
        com.kingdee.bos.dao.IObjectPK excTablepk = null;
        com.kingdee.bos.dao.IObjectPK destCurrpk = null;
        if(companyOrgUnitInfo == null)
            companyOrgUnitInfo = getCompanyInfo(ctx);
        if(companyOrgUnitInfo.getBaseExchangeTable() != null)
            excTablepk = new ObjectUuidPK(companyOrgUnitInfo.getBaseExchangeTable().getId());
        else
            return null;
        CurrencyInfo baseCur = companyOrgUnitInfo.getBaseCurrency();
        if(baseCur != null)
        {
            if(baseCur.getId().equals(currencyInfo.getId()))
                return null;
            destCurrpk = new ObjectUuidPK(baseCur.getId());
        } else
        {
            return null;
        }
        iexchangRate = ExchangeRateFactory.getLocalInstance(ctx);
        com.kingdee.bos.dao.IObjectPK sourceCurrpk = new ObjectUuidPK(currencyInfo.getId());
        ExchangeRateInfo erInfo = iexchangRate.getExchangeRate(excTablepk, sourceCurrpk, destCurrpk, Calendar.getInstance().getTime());
        return erInfo;
    }

    private static CompanyOrgUnitInfo getCompanyInfo(Context ctx)
        throws Exception
    {
        CompanyOrgUnitInfo defalutOrgInfo = null;
        ObjectUuidPK compk = getCompanyPK(ctx);
        ICompanyOrgUnit comorg = null;
        comorg = CompanyOrgUnitFactory.getLocalInstance(ctx);
        SelectorItemCollection sic = new SelectorItemCollection();
        sic.add(new SelectorItemInfo("number"));
        sic.add(new SelectorItemInfo("name"));
        sic.add(new SelectorItemInfo("accountBank.id"));
        sic.add(new SelectorItemInfo("accountBank.name"));
        sic.add(new SelectorItemInfo("accountBank.number"));
        sic.add(new SelectorItemInfo("baseCurrency"));
        sic.add(new SelectorItemInfo("baseCurrency.name"));
        sic.add(new SelectorItemInfo("baseCurrency.precision"));
        sic.add(new SelectorItemInfo("baseExchangeTable"));
        sic.add(new SelectorItemInfo("CU.*"));
        sic.add(new SelectorItemInfo("invalidDate"));
        sic.add(new SelectorItemInfo("isOnlyUnion"));
        defalutOrgInfo = comorg.getCompanyOrgUnitInfo(compk, sic);
        return defalutOrgInfo;
    }

    protected static OtherBillTypeEnum getARBillType(Hashtable hsData, String field)
        throws TaskExternalException
    {
        OtherBillTypeEnum billTypeEnum = null;
        int tempType = getDataInt(hsData, field);
        if(tempType == 0)
            throw new TaskExternalException(ResourceBase.getString("com.kingdee.eas.fi.arap.ARAPAutoGenerateResource", "147_ARAPImportHelper", SysContext.getSysContext().getLocale()));
        switch(getDataInt(hsData, field))
        {
        case 101: // 'e'
            billTypeEnum = OtherBillTypeEnum.OtherReceivable;
            break;
        case 104: // 'e'
            billTypeEnum = OtherBillTypeEnum.DebitAdjust;
            break;

        case 102: // 'f'
            billTypeEnum = OtherBillTypeEnum.InvoiceBill;
            break;

        case 103: // 'g'
            billTypeEnum = OtherBillTypeEnum.ExpenseInvoice;
            break;
        }
        if(billTypeEnum == null)
            throw new TaskExternalException(ResourceBase.getString("com.kingdee.eas.fi.arap.ARAPAutoGenerateResource", "148_ARAPImportHelper", SysContext.getSysContext().getLocale()));
        else
            return billTypeEnum;
    }

    protected static OtherBillType getAPBillType(Hashtable hsData, String field)
        throws TaskExternalException
    {
        OtherBillType billTypeEnum = null;
        int a =getDataInt(hsData, field);
        switch(getDataInt(hsData, field))
        {
        case 201: 
            billTypeEnum = OtherBillType.OtherPay;
            break;

        case 202: 
            billTypeEnum = OtherBillType.InvoiceBill;
            break;

        case 203: 
            billTypeEnum = OtherBillType.ExpenseInvoice;
            break;
        case 204: 
            billTypeEnum = OtherBillType.DebitAdjust;
            break;
        }
        if(billTypeEnum == null)
            throw new TaskExternalException("BillType_Wrong");
        else
            return billTypeEnum;
    }

    protected static void setAPBillAmtFromEntry(OtherBillInfo otherBillInfo, OtherBillentryInfo otherBillentryInfo, boolean isUpdateEntry)
    {
        OtherBillentryCollection c = otherBillInfo.getEntry();
        BigDecimal temp = new BigDecimal(0.0D);
        BigDecimal tempVeriy = new BigDecimal(0.0D);
        BigDecimal tempUnVeriy = new BigDecimal(0.0D);
        BigDecimal tempAmountLocal = new BigDecimal(0.0D);
        BigDecimal tempVerifyAmountLocal = new BigDecimal(0.0D);
        BigDecimal tempUnVeriyAmountLocal = new BigDecimal(0.0D);
        BigDecimal exchangeRate = otherBillInfo.getExchangeRate();
        boolean isRedBill = otherBillentryInfo.isRed();
        ArApBillHelper.handleRedBill(otherBillentryInfo, isRedBill);
        if(c.size() == 0)
        {
            temp = temp.add(otherBillentryInfo.getRecievePayAmount());
            tempUnVeriy = tempUnVeriy.add(otherBillentryInfo.getUnVerifyAmount());
            tempVeriy = tempVeriy.add(otherBillentryInfo.getVerifyAmount());
            tempAmountLocal = tempAmountLocal.add(otherBillentryInfo.getRecievePayAmountLocal());
            tempVerifyAmountLocal = tempVerifyAmountLocal.add(otherBillentryInfo.getVerifyAmountLocal());
            tempUnVeriyAmountLocal = tempUnVeriyAmountLocal.add(otherBillentryInfo.getUnVerifyAmountLocal());
        } else
        {
            Iterator itrEntry = c.iterator();
            if(!isUpdateEntry)
            {
                while(itrEntry.hasNext()) 
                {
                    OtherBillentryInfo entryTmp = (OtherBillentryInfo)itrEntry.next();
                    temp = temp.add(entryTmp.getRecievePayAmount());
                    tempUnVeriy = tempUnVeriy.add(entryTmp.getUnVerifyAmount());
                    tempVeriy = tempVeriy.add(entryTmp.getVerifyAmount());
                    tempAmountLocal = tempAmountLocal.add(entryTmp.getRecievePayAmountLocal());
                    tempVerifyAmountLocal = tempVerifyAmountLocal.add(entryTmp.getVerifyAmountLocal());
                    tempUnVeriyAmountLocal = tempUnVeriyAmountLocal.add(entryTmp.getUnVerifyAmountLocal());
                }
                temp = temp.add(otherBillentryInfo.getRecievePayAmount());
                tempUnVeriy = tempUnVeriy.add(otherBillentryInfo.getUnVerifyAmount());
                tempVeriy = tempVeriy.add(otherBillentryInfo.getVerifyAmount());
                tempAmountLocal = tempAmountLocal.add(otherBillentryInfo.getRecievePayAmountLocal());
                tempVerifyAmountLocal = tempVerifyAmountLocal.add(otherBillentryInfo.getVerifyAmountLocal());
                tempUnVeriyAmountLocal = tempUnVeriyAmountLocal.add(otherBillentryInfo.getUnVerifyAmountLocal());
            } else
            {
                while(itrEntry.hasNext()) 
                {
                    OtherBillentryInfo entryTmp = (OtherBillentryInfo)itrEntry.next();
                    if(entryTmp.getSeq() == otherBillentryInfo.getSeq())
                    {
                        temp = temp.add(otherBillentryInfo.getRecievePayAmount());
                        tempUnVeriy = tempUnVeriy.add(otherBillentryInfo.getUnVerifyAmount());
                        tempVeriy = tempVeriy.add(otherBillentryInfo.getVerifyAmount());
                        tempAmountLocal = tempAmountLocal.add(otherBillentryInfo.getRecievePayAmountLocal());
                        tempVerifyAmountLocal = tempVerifyAmountLocal.add(otherBillentryInfo.getVerifyAmountLocal());
                        tempUnVeriyAmountLocal = tempUnVeriyAmountLocal.add(otherBillentryInfo.getUnVerifyAmountLocal());
                    } else
                    {
                        temp = temp.add(entryTmp.getRecievePayAmount());
                        tempUnVeriy = tempUnVeriy.add(entryTmp.getUnVerifyAmount());
                        tempVeriy = tempVeriy.add(entryTmp.getVerifyAmount());
                        tempAmountLocal = tempAmountLocal.add(entryTmp.getRecievePayAmountLocal());
                        tempVerifyAmountLocal = tempVerifyAmountLocal.add(entryTmp.getVerifyAmountLocal());
                        tempUnVeriyAmountLocal = tempUnVeriyAmountLocal.add(entryTmp.getUnVerifyAmountLocal());
                    }
                }
            }
        }
        otherBillInfo.setAmount(temp);
        otherBillInfo.setUnVerifyAmount(tempUnVeriy);
        otherBillInfo.setVerifyAmount(tempVeriy);
        otherBillInfo.setAmountLocal(tempAmountLocal);
        otherBillInfo.setVerifyAmountLocal(tempVerifyAmountLocal);
        otherBillInfo.setUnVerifyAmountLocal(tempUnVeriyAmountLocal);
        exchangeRate = exchangeRate.compareTo(ZERO) != 0 ? exchangeRate : ONE;
        otherBillInfo.setExchangeRate(exchangeRate);
    }

    protected static void setARBillAmtFromEntry(com.kingdee.eas.fi.ar.OtherBillInfo otherBillInfo, com.kingdee.eas.fi.ar.OtherBillentryInfo otherBillentryInfo, boolean isUpdateEntry)
    {
        com.kingdee.eas.fi.ar.OtherBillentryCollection c = otherBillInfo.getEntry();
        BigDecimal temp = new BigDecimal(0.0D);
        BigDecimal tempAmountLocal = new BigDecimal(0.0D);
        BigDecimal tempVeriy = new BigDecimal(0.0D);
        BigDecimal tempUnVeriy = new BigDecimal(0.0D);
        BigDecimal tempVerifyAmountLocal = new BigDecimal(0.0D);
        BigDecimal tempUnVeriyAmountLocal = new BigDecimal(0.0D);
        BigDecimal exchangeRate = otherBillInfo.getExchangeRate();
        boolean isRedBill = otherBillentryInfo.isRed();
        ArApBillHelper.handleRedBill(otherBillentryInfo, isRedBill);
        if(c.size() == 0)
        {
            temp = temp.add(otherBillentryInfo.getRecievePayAmount());
            tempAmountLocal = tempAmountLocal.add(otherBillentryInfo.getRecievePayAmountLocal());
            tempUnVeriy = tempUnVeriy.add(otherBillentryInfo.getUnVerifyAmount());
            tempVeriy = tempVeriy.add(otherBillentryInfo.getVerifyAmount());
            tempVerifyAmountLocal = tempVerifyAmountLocal.add(otherBillentryInfo.getVerifyAmountLocal());
            tempUnVeriyAmountLocal = tempUnVeriyAmountLocal.add(otherBillentryInfo.getUnVerifyAmountLocal());
        } else
        {
            Iterator itrEntry = c.iterator();
            if(!isUpdateEntry)
            {
                while(itrEntry.hasNext()) 
                {
                    com.kingdee.eas.fi.ar.OtherBillentryInfo entryTmp = (com.kingdee.eas.fi.ar.OtherBillentryInfo)itrEntry.next();
                    temp = temp.add(entryTmp.getRecievePayAmount());
                    tempAmountLocal = tempAmountLocal.add(entryTmp.getRecievePayAmountLocal());
                    tempUnVeriy = tempUnVeriy.add(entryTmp.getUnVerifyAmount());
                    tempVeriy = tempVeriy.add(entryTmp.getVerifyAmount());
                    tempVerifyAmountLocal = tempVerifyAmountLocal.add(entryTmp.getVerifyAmountLocal());
                    tempUnVeriyAmountLocal = tempUnVeriyAmountLocal.add(entryTmp.getUnVerifyAmountLocal());
                }
                temp = temp.add(otherBillentryInfo.getRecievePayAmount());
                tempAmountLocal = tempAmountLocal.add(otherBillentryInfo.getRecievePayAmountLocal());
                tempUnVeriy = tempUnVeriy.add(otherBillentryInfo.getUnVerifyAmount());
                tempVeriy = tempVeriy.add(otherBillentryInfo.getVerifyAmount());
                tempVerifyAmountLocal = tempVerifyAmountLocal.add(otherBillentryInfo.getVerifyAmountLocal());
                tempUnVeriyAmountLocal = tempUnVeriyAmountLocal.add(otherBillentryInfo.getUnVerifyAmountLocal());
            } else
            {
                while(itrEntry.hasNext()) 
                {
                    com.kingdee.eas.fi.ar.OtherBillentryInfo entryTmp = (com.kingdee.eas.fi.ar.OtherBillentryInfo)itrEntry.next();
                    if(entryTmp.getSeq() == otherBillentryInfo.getSeq())
                    {
                        temp = temp.add(otherBillentryInfo.getRecievePayAmount());
                        tempAmountLocal = tempAmountLocal.add(otherBillentryInfo.getRecievePayAmountLocal());
                        tempUnVeriy = tempUnVeriy.add(otherBillentryInfo.getUnVerifyAmount());
                        tempVeriy = tempVeriy.add(otherBillentryInfo.getVerifyAmount());
                        tempVerifyAmountLocal = tempVerifyAmountLocal.add(otherBillentryInfo.getVerifyAmountLocal());
                        tempUnVeriyAmountLocal = tempUnVeriyAmountLocal.add(otherBillentryInfo.getUnVerifyAmountLocal());
                    } else
                    {
                        temp = temp.add(entryTmp.getRecievePayAmount());
                        tempAmountLocal = tempAmountLocal.add(entryTmp.getRecievePayAmountLocal());
                        tempUnVeriy = tempUnVeriy.add(entryTmp.getUnVerifyAmount());
                        tempVeriy = tempVeriy.add(entryTmp.getVerifyAmount());
                        tempVerifyAmountLocal = tempVerifyAmountLocal.add(entryTmp.getVerifyAmountLocal());
                        tempUnVeriyAmountLocal = tempUnVeriyAmountLocal.add(entryTmp.getUnVerifyAmountLocal());
                    }
                }
            }
        }
        otherBillInfo.setAmount(temp);
        otherBillInfo.setAmountLocal(tempAmountLocal);
        otherBillInfo.setUnVerifyAmount(tempUnVeriy);
        otherBillInfo.setVerifyAmount(tempVeriy);
        otherBillInfo.setVerifyAmountLocal(tempVerifyAmountLocal);
        otherBillInfo.setUnVerifyAmountLocal(tempUnVeriyAmountLocal);
        exchangeRate = exchangeRate.compareTo(ZERO) != 0 ? exchangeRate : ONE;
        otherBillInfo.setExchangeRate(exchangeRate);
    }

    protected static boolean checkAPAmtIsOver(OtherBillInfo otherBillInfo, OtherBillPlanInfo planInfo, boolean isUpdatePlan)
    {
        boolean flag = false;
        OtherBillPlanCollection collection = otherBillInfo.getPayPlan();
        BigDecimal temp = new BigDecimal("0.00");
        BigDecimal amount = otherBillInfo.getAmount();
        Iterator iter = collection.iterator();
        if(!isUpdatePlan)
        {
            while(iter.hasNext()) 
            {
                OtherBillPlanInfo tempPlanInfo = (OtherBillPlanInfo)iter.next();
                temp = temp.add(tempPlanInfo.getRecievePayAmount());
            }
            temp = temp.add(planInfo.getRecievePayAmount());
        } else
        {
            while(iter.hasNext()) 
            {
                OtherBillPlanInfo tempPlanInfo = (OtherBillPlanInfo)iter.next();
                if(tempPlanInfo.getSeq() == planInfo.getSeq())
                    temp = temp.add(planInfo.getRecievePayAmount());
                else
                    temp = temp.add(tempPlanInfo.getRecievePayAmount());
            }
        }
        if(temp.compareTo(amount) > 0)
            flag = true;
        return flag;
    }

    public static String getString(String resName, Context ctx)
    {
        return getString("AR", resName, ctx);
    }

    public static String getString(String SysType, String resName, Context ctx)
    {
        String AR_RESOURCE_PATH = "com.kingdee.eas.fi.ar.ARImportData";
        String AP_RESOURCE_PATH = "com.kingdee.eas.fi.ap.APImportData";
        if(SysType.equalsIgnoreCase("AR"))
            return ResourceBase.getString(AR_RESOURCE_PATH, resName, ctx.getLocale());
        if(SysType.equalsIgnoreCase("AP"))
            return ResourceBase.getString(AP_RESOURCE_PATH, resName, ctx.getLocale());
        else
            return null;
    }

    public static String getDataString(Hashtable hsData, String field)
    {
        String reStr = null;
        if(hsData != null && field != null && field.trim().length() > 0)
        {
            DataToken dt = (DataToken)hsData.get(field);
            if(dt != null && dt.data != null && dt.data.toString().trim().length() > 0)
                reStr = dt.data.toString().trim();
        }
        return reStr;
    }

    public static Date getDataDate(Context ctx, Hashtable hsData, String field)
        throws TaskExternalException
    {
        Date reDate = null;
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String reStr = getDataString(hsData, field);
        if(reStr != null)
            try
            {
                reDate = df.parse(reStr);
            }
            catch(ParseException e)
            {
                String msg = getString("DateFormat_Wrong", ctx);
                msg = MessageFormat.format(msg, new String[] {
                    field
                });
                throw new TaskExternalException(msg);
            }
        return reDate;
    }

    public static BigDecimal getDataDeciaml(Context ctx, Hashtable hsData, String field)
        throws TaskExternalException
    {
        BigDecimal reVal = ZERO;
        String reStr = getDataString(hsData, field);
        if(reStr != null)
            try
            {
                reVal = new BigDecimal(reStr);
            }
            catch(Exception nex)
            {
                String msg = getString("NumberField_Wrong", ctx);
                msg = MessageFormat.format(msg, new String[] {
                    field
                });
                throw new TaskExternalException(msg);
            }
        return reVal;
    }

    public static int getDataInt(Hashtable hsData, String field)
        throws TaskExternalException
    {
        int reInt = 0;
        String reStr = getDataString(hsData, field);
        if(reStr != null)
            try
            {
                reInt = Integer.parseInt(reStr);
            }
            catch(Exception e)
            {
                throw new TaskExternalException(ResourceBase.getString("com.kingdee.eas.fi.arap.ARAPAutoGenerateResource", "149_ARAPImportHelper", SysContext.getSysContext().getLocale()));
            }
        return reInt;
    }

    public static BillTypeInfo getBillType(Context ctx, Hashtable hsData, String field)
        throws TaskExternalException
    {
        BillTypeInfo billType = null;
        String number = getDataString(hsData, field);
        try
        {
            if(number != null)
            {
                BillTypeCollection billTypes = BillTypeFactory.getLocalInstance(ctx).getBillTypeCollection(getEntityViewByNum(number));
                if(billTypes == null || billTypes.size() == 0)
                    throw new TaskExternalException(getString("CoreBillTypeError", ctx));
                billType = billTypes.get(0);
            }
        }
        catch(BOSException ex)
        {
            throw new TaskExternalException(getString("CoreBillTypeError", ctx), ex);
        }
        return billType;
    }

    public static int getCoreBillSeq(Context ctx, Hashtable hsData)
        throws TaskExternalException
    {
        return getCoreBillSeq(ctx, hsData, "FCoreBillSeq");
    }

    public static int getCoreBillSeq(Context ctx, Hashtable hsData, String filedName)
        throws TaskExternalException
    {
        int seq = 0;
        try
        {
            seq = getDataInt(hsData, filedName);
        }
        catch(Exception ex)
        {
            throw new TaskExternalException(getString("CoreBillSeqError", ctx), ex);
        }
        return seq;
    }

    public static PaymentBillTypeInfo getPaymentBillType(Context ctx, Hashtable hsData, String filedName)
        throws TaskExternalException
    {
        PaymentBillTypeInfo payTypeInfo = null;
        String number = getDataString(hsData, filedName);
        if(number != null)
            try
            {
                PaymentBillTypeCollection colls = PaymentBillTypeFactory.getLocalInstance(ctx).getPaymentBillTypeCollection(getEntityViewByNum(number));
                if(colls != null && colls.size() > 0)
                    payTypeInfo = colls.get(0);
            }
            catch(BOSException e)
            {
                throw new TaskExternalException(getString("PayBillType_Is_Null", ctx), e);
            }
        if(payTypeInfo == null)
            throw new TaskExternalException(getString("PayBillType_Is_Null", ctx));
        else
            return payTypeInfo;
    }

    public static ReceivingBillTypeInfo getReceivingBillType(Context ctx, Hashtable hsData, String filedName)
        throws TaskExternalException
    {
        ReceivingBillTypeInfo recTypeInfo = null;
        String number = getDataString(hsData, filedName);
        if(number != null)
            try
            {
                ReceivingBillTypeCollection colls = ReceivingBillTypeFactory.getLocalInstance(ctx).getReceivingBillTypeCollection(getEntityViewByNum(number));
                if(colls != null && colls.size() > 0)
                    recTypeInfo = colls.get(0);
            }
            catch(BOSException e)
            {
                throw new TaskExternalException(getString("RecBillType_Is_Null", ctx), e);
            }
        if(recTypeInfo == null)
            throw new TaskExternalException(getString("RecBillType_Is_Null", ctx));
        else
            return recTypeInfo;
    }

    public static int checkIsIntStr(String str)
    {
        int reInt = -1;
        if(str != null && str.trim().length() > 0)
            try
            {
                reInt = Integer.parseInt(str);
            }
            catch(NumberFormatException e) { }
        return reInt;
    }

    public static final String AR_DECIMAL_FIELDS[] = {
        "FExchangeRate", "FTotalBadAmount", "FTotalBadAmountLocal"
    };
    public static final String AR_DECIMAL_OBJS[] = {
        "exchangeRate", "totalBadAmount", "totalBadAmountLocal"
    };
    public static final String FCOREBILLSEQ = "FCoreBillSeq";
    public static final String AR_ENTRY_DECIMAL_FIELDS[] = {
        "FRecievePayAmount_E", "FRecievePayAmountLocal_E", "FVerifyAmount_E", "FVerifyAmountLocal_E", "FQuantity", "FPrice", "FTaxPrice", "FTaxRate", "FTaxAmount", "FBadAmout", 
        "FLocalBadAmout", "FTaxAmountLocal", "FActualPrice", "FDiscountRate", "FDiscountAmount", "FAmount_E", "FAmountLocal_E", "FAssistQty", "FRealPrice"
    };
    public static final String AR_ENTRY_DECIMAL_OBJS[] = {
        "recievePayAmount", "recievePayAmountLocal", "verifyAmount", "verifyAmountLocal", "quantity", "price", "taxPrice", "taxRate", "taxAmount", "badAmount", 
        "localBadAmout", "taxAmountLocal", "actualPrice", "discountRate", "discountAmount", "amount", "amountLocal", "assistQty", "realPrice"
    };
    protected static final String AP_DECIMAL_FIELDS[] = {
        "FExchangeRate"
    };
    protected static final String AP_DECIMAL_OBJS[] = {
        "exchangeRate"
    };
    protected static final String AP_ENTRY_DECIMAL_FIELDS[] = {
        "FRecievePayAmount_E", "FRecievePayAmountLocal_E", "FVerifyAmount_E", "FVerifyAmountLocal_E", "FQuantity", "FPrice", "FTaxPrice", "FTaxRate", "FTaxAmount", "FTaxAmountLocal", 
        "FActualPrice", "FDiscountRate", "FDiscountAmount", "FAmount_E", "FAmountLocal_E", "FAssistQty", "FRealPrice"
    };
    protected static final String AP_ENTRY_DECIMAL_OBJS[] = {
        "recievePayAmount", "recievePayAmountLocal", "verifyAmount", "verifyAmountLocal", "quantity", "price", "taxPrice", "taxRate", "taxAmount", "taxAmountLocal", 
        "actualPrice", "discountRate", "discountAmount", "amount", "amountLocal", "assistQty", "realPrice"
    };
    public static final String DATE_FIELDS[] = {
        "FBillDate", "FBizDate"
    };
    public static final String DATE_OBJS[] = {
        "billDate", "bizDate"
    };
    public static final String STRING_FIELDS[] = {
        "FNumber", "FAsstActNumber", "FAbstractName"
    };
    public static final String STRING_OBJS[] = {
        "number", "asstActNumber", "abstractName"
    };
    public static final String ENTRY_STRING_FIELDS[] = {
        "FRemark_E", "FCoreBillNum"
    };
    public static final String ENTRY_STRING_OBJS[] = {
        "remark", "coreBillNumber"
    };
    public static final BigDecimal ZERO = new BigDecimal("0.00");
    public static final BigDecimal ONE = new BigDecimal("1.00");

}


/*
	DECOMPILATION REPORT

	Decompiled from: D:\workspace_demo\EAS701BT\lib\server\eas\fi_arap-server.jar
	Total time: 733 ms
	Jad reported messages/errors:
	Exit status: 0
	Caught exceptions:
*/